/**
 *
 */
package com.ssyt.examinationsystem.service.impl;

import com.ssyt.examinationsystem.dao.ICourseInfoDAO;
import com.ssyt.examinationsystem.dao.impl.CourseInfoDAOImpl;
import com.ssyt.examinationsystem.entity.CourseInfo;
import com.ssyt.examinationsystem.service.ICourseInfoService;
import com.ssyt.examinationsystem.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class CourseInfoServiceImpl implements ICourseInfoService {
    // 创建一个数据层对象
    ICourseInfoDAO courseDao = new CourseInfoDAOImpl();

    @Override
    public List<CourseInfo> getCourseInfos() {
        // 创建一个集合对象
        List<CourseInfo> courseList = new ArrayList<CourseInfo>();
        // 调用查询所有的科目的业务方法
        List<Map<String, Object>> list = courseDao.getCourseInfos();
        if (CollectionUtils.isEmptyForList(list)) {
            for (Map<String, Object> map : list) {

                // 创建一个科目对象，封装属性
                CourseInfo course = new CourseInfo();
                course.setCourseId(Integer.valueOf(String.valueOf(map.get("courseId"))));
                course.setCourseName(String.valueOf(map.get("courseName")));
                // 添加到存放科目对象的集合中
                courseList.add(course);
            }
        }
        return courseList;
    }

    @Override
    public int addCourseInfo(CourseInfo course) {
        return courseDao.addCourseInfo(course);
    }

    @Override
    public int deleteCourseInfo(String courseId) {
        return courseDao.deleteCourseInfo(courseId);
    }

    @Override
    public Map<String, Object> getCourseInfoByRoleId(String courseId) {
        return courseDao.getCourseInfoByRoleId(courseId);
    }

    @Override
    public int updateCourseInfo(CourseInfo course) {
        return courseDao.updateCourseInfo(course);
    }

}
